package fr.uniscol.dao.mapper;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import fr.uniscol.model.BaseAnneeScolaire;
import fr.uniscol.model.DefaultUser;
import fr.uniscol.model.EtablissementModel;
import fr.uniscol.model.IUniscolUser;

public class UserModelRowMapper implements RowMapper<DefaultUser> {

	@Override
	public DefaultUser mapRow(ResultSet rs, int line) throws SQLException {
		
		DefaultUser user = new DefaultUser();
		((DefaultUser)user).setId(rs.getLong("ID"));
		((DefaultUser)user).setLogin(rs.getString("LOGIN"));
        ((DefaultUser)user).setNom(rs.getString("NOM"));
        ((DefaultUser)user).setPrenom(rs.getString("PRENOM"));
		
		if(rs.getString("BASEID") != null){
			((DefaultUser)user).setBaseSelectionnee(new BaseAnneeScolaire());
			((DefaultUser)user).getBaseSelectionnee().setId(rs.getLong("BASEID"));
		}
		
		return user;
	}
}
